<?php
namespace app\admin\controller;

use app\admin\controller\AdminBaseController;
use think\Cache;
use think\Db;

/**
 * 统计
 * Class System
 */
class TongjiController extends BaseController {
	
	
	//会员公益
	public function gongyi($user_name='',$mobile='',$start_time='',$end_time=''){
		$where['a.order_type']=['in',[1,2]];
        if($user_name){
			$where['b.user_name']=array('like',"%".$user_name."%");
		}
		$this->assign("user_name",$user_name);
		if(input('mobile')){
			$where['b.mobile']=array('like',"%".$mobile."%");
		}
		$this->assign("mobile",$mobile);
		if(input("start_time")&&input("end_time")){
			$where['a.add_time']=['between',[input('start_time'),input('end_time')]];
		}elseif(input("start_time")){
			$where['a.add_time']=['>=',input("start_time")];
		}elseif(input("end_time")){
			$where['a.add_time']=['<=',input("end_time")];
		}
		$this->assign("start_time",$start_time);
		$this->assign("end_time",$end_time);
		
		$field="a.*,b.mobile,b.nick_name";
        $member_list = db('member_gongyi')->alias("a")->
        join("member b","b.user_id=a.user_id")->where($where)->field($field)->order("a.add_time desc")->paginate(15, false, get_query());
        return $this->fetch('', ['list' => $member_list]);
	}
		//会员余额记录
	public function m_balance($user_name='',$mobile='',$start_time='',$end_time=''){
		$where = [];
        if($user_name){
			$where['b.user_name']=array('like',"%".$user_name."%");
		}
		$this->assign("user_name",$user_name);
		if(input('mobile')){
			$where['b.mobile']=array('like',"%".$mobile."%");
		}
		$this->assign("mobile",$mobile);
		if(input("start_time")&&input("end_time")){
			$where['a.add_time']=['between',[input('start_time'),input('end_time')]];
		}elseif(input("start_time")){
			$where['a.add_time']=['>=',input("start_time")];
		}elseif(input("end_time")){
			$where['a.add_time']=['<=',input("end_time")];
		}
		$this->assign("start_time",$start_time);
		$this->assign("end_time",$end_time);
		$field="a.*,b.mobile,b.nick_name";
        $member_list = db('member_charge')->alias("a")->
        join("member b","b.user_id=a.user_id")->where($where)->field($field)->order("a.add_time desc")->paginate(15, false, get_query());
        return $this->fetch('', ['list' => $member_list]);
	}
	//会员消费记录
	public function m_xiaofei($user_name='',$mobile='',$start_time='',$end_time=''){
		$where['a.order_type']=['in',[1,2]];
        if($user_name){
			$where['b.user_name']=array('like',"%".$user_name."%");
		}
		$this->assign("user_name",$user_name);
		if(input('mobile')){
			$where['b.mobile']=array('like',"%".$mobile."%");
		}
		$this->assign("mobile",$mobile);
		if(input("start_time")&&input("end_time")){
			$where['a.add_time']=['between',[input('start_time'),input('end_time')]];
		}elseif(input("start_time")){
			$where['a.add_time']=['>=',input("start_time")];
		}elseif(input("end_time")){
			$where['a.add_time']=['<=',input("end_time")];
		}
		$this->assign("start_time",$start_time);
		$this->assign("end_time",$end_time);
		
		$field="a.*,b.mobile,b.nick_name";
        $member_list = db('member_consume')->alias("a")->
        join("member b","b.user_id=a.user_id")->where($where)->field($field)->order("a.add_time desc")->paginate(15, false, get_query());
        return $this->fetch('', ['list' => $member_list]);
	}
	//商家余额记录
	public function a_balance($agent_name='',$mobile='',$start_time='',$end_time=''){
		$where = [];
        if($agent_name){
			$where['b.agent_name']=array('like',"%".$agent_name."%");
		}
		$this->assign("agent_name",$agent_name);
		if(input('mobile')){
			$where['b.mobile']=array('like',"%".$mobile."%");
		}
		$this->assign("mobile",$mobile);
		if(input("start_time")&&input("end_time")){
			$where['a.add_time']=['between',[input('start_time'),input('end_time')]];
		}elseif(input("start_time")){
			$where['a.add_time']=['>=',input("start_time")];
		}elseif(input("end_time")){
			$where['a.add_time']=['<=',input("end_time")];
		}
		$this->assign("start_time",$start_time);
		$this->assign("end_time",$end_time);
		
		$field="a.*,b.mobile,b.agent_name";
        $member_list = db('agent_charge')->alias("a")->
        join("agent b","b.id=a.agent_id")->where($where)->field($field)->order("a.add_time desc")->paginate(15, false, get_query());
        return $this->fetch('', ['list' => $member_list]);
	}
	//代理商余额记录
	public function o_balance($user_name='',$mobile='',$start_time='',$end_time=''){
		$where = [];
        if($user_name){
			$where['b.user_name']=array('like',"%".$user_name."%");
		}
		$this->assign("user_name",$user_name);
		if(input('mobile')){
			$where['b.mobile']=array('like',"%".$mobile."%");
		}
		$this->assign("mobile",$mobile);
		if(input("start_time")&&input("end_time")){
			$where['a.add_time']=['between',[input('start_time'),input('end_time')]];
		}elseif(input("start_time")){
			$where['a.add_time']=['>=',input("start_time")];
		}elseif(input("end_time")){
			$where['a.add_time']=['<=',input("end_time")];
		}
		$this->assign("start_time",$start_time);
		$this->assign("end_time",$end_time);
		
		$field="a.*,b.mobile,b.user_name";
        $member_list = db('oem_charge')->alias("a")->
        join("oem b","b.id=a.oem_id")->where($where)->field($field)->order("a.add_time desc")->paginate(15, false, get_query());
        return $this->fetch('', ['list' => $member_list]);
	}
		
	
}
